<template>
	<uni-table stripe v-bind="$attrs">
		<uni-tr v-if="haeder">
			<template v-for="item in columns" :key="item.label">
				<uni-th v-bind="item">{{item.label}}</uni-th>
			</template>
		</uni-tr>
		<uni-tr v-for="(row, $index) in data" :key="$index">
			<template v-for="(column,colIndex) in columns">
				<uni-td v-bind="{...column,...row}">
					<slot :name="column.prop || 'default'" v-bind="{row, column, $index}">
						{{column?.formatter?.(row, column, row[column.prop], $index) || row[column.prop]}}
					</slot>
				</uni-td>
			</template>
		</uni-tr>
	</uni-table>
</template>

<script setup>
	/***
	 * props
	 * @property {Array} [columns = []]  表格列定义，对象属性参数完全继承 uni-th
	 * @property {Array} [data = []]  表格数据
	 */
	const props = defineProps({
		data: {
			type: Array,
			default () {
				return [];
			},
		},
		columns: {
			type: Array,
			default () {
				return [];
			},
		},
		haeder: {
			type: Boolean,
			default: true
		}
	});
</script>